package com.herench.bunch.clinic.handler;

import com.alibaba.fastjson.JSON;
import com.herench.bunch.clinic.agent.ClinicAgent;
import com.herench.bunch.clinic.convert.CheckBillConvert;
import com.herench.bunch.clinic.support.ProxyMsgTemplate;
import com.herench.bunch.commons.annotation.Handler;
import com.herench.bunch.commons.support.AbstractMessageHandler;
import org.dom4j.Document;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Handler(code = "200250", name = "查询对账数据信息" ,messageConvertClass = CheckBillConvert.class)
public class CheckBillHandlerClinic extends AbstractMessageHandler {


    @Autowired
    private ClinicAgent clinicAgent;

    @Override
    protected Object proxyInvoke(Object inMessage) throws Exception {
        Document message = (Document) inMessage;
        Document doc = ProxyMsgTemplate.getOutMsgTpl(message.asXML());
        Map<String,Object> params = new HashMap<>();
        params.put("startDate",doc.getRootElement().elementTextTrim("startDate"));
        params.put("endDate",doc.getRootElement().elementTextTrim("endDate"));
        List<Map<String,Object>> res = clinicAgent.checkBill(params);
        String req = JSON.toJSONString(res);
        return req;
    }
}
